# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=leptonica
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.80.0
pkgrel=1
pkgdesc="Leptonica library (mingw-w64)"
arch=('any')
url="http://www.leptonica.org"
license=("Leptonica")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
checkdepends=("${MINGW_PACKAGE_PREFIX}-gnuplot")
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs
         ${MINGW_PACKAGE_PREFIX}-giflib
         ${MINGW_PACKAGE_PREFIX}-libtiff
         ${MINGW_PACKAGE_PREFIX}-libpng
         ${MINGW_PACKAGE_PREFIX}-libwebp
         ${MINGW_PACKAGE_PREFIX}-openjpeg2
         ${MINGW_PACKAGE_PREFIX}-zlib)
options=('!libtool' 'strip')
source=(https://github.com/DanBloomberg/leptonica/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz)
sha256sums=('ec9c46c2aefbb960fb6a6b7f800fe39de48343437b6ce08e30a8d9688ed14ba4')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${CARCH}" ]] && rm -rf "${srcdir}/build-${CARCH}"
  mkdir -p "${srcdir}/build-${CARCH}" && cd "${srcdir}/build-${CARCH}"
  CFLAGS+=" -DMINIMUM_SEVERITY=L_SEVERITY_WARNING"
  ../${_realname}-${pkgver}/configure -C \
    --disable-dependency-tracking \
    --disable-silent-rules \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}
  make
}

check() {
  cd "${srcdir}/build-${CARCH}"
  make -j1 check
}

package() {
  cd "${srcdir}/build-${CARCH}"
  make DESTDIR="${pkgdir}" install

  # Fix .pc file
  sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/lept.pc
}
